<?php

namespace Admin\Controller;

use Common\Controller\AdminbaseController;

class AdminConfigController extends AdminbaseController {

    protected $m_config;

    function _initialize() {
        parent::_initialize();
        $this->m_config= D("Admin/Config");
    }


    /**
     * 配置管理
     */
    public function index(){
        $user = M("Users")->where(array("id"=>session('ADMIN_ID')))->find();
        if($user['model'] == 4){
            $where = "`key`='admin_card_give_price' OR `key`='admin_card_active_price' OR `key`='admin_card_sale_point'";
        }elseif($user['model'] == 2){
            $where = "`key`='logistics_card_give_price' OR `key`='logistics_card_sale_point'";
        }

        $count=$this->m_config->where($where)->count();
        $page = $this->page($count, 15);
        $list = $this->m_config->where($where)->order("create_time desc")
            ->limit($page->firstRow , $page->listRows)
            ->select();
        $this->assign("page", $page->show('Admin'));
        $this->assign("list",$list);
        $this->display();
    }


    // 添加物流公司
    public function add(){
        $id = I("get.id",0,'intval');
        if(!empty($id)){
            $item=$this->m_config->where(array('id'=>$id))->find();
            $this->assign("item",$item);
        }

        $this->display();
    }

    // 提交
    public function add_post(){
        if (IS_POST) {
            $id = I("post.id");
            $insert = I("post.");

            if(empty($id)){
                $insert['create_time'] =time();
                $result =$this->m_config->add($insert);
            }else{

                $result = $this->m_config->where(array("id"=>$id))->save($insert);
            }
            if ($result) {
                $this->success("添加成功！");
            } else {
                $this->error("添加失败！");
            }

        }
    }



}